import pika
import json

#建立连接
userx=pika.PlainCredentials("ruroot","rproot")
conn=pika.BlockingConnection(pika.ConnectionParameters("0.0.0.0",5672,'/',credentials=userx))

#开辟管道
channelx=conn.channel()

#声明队列，参数为队列名
channelx.queue_declare(queue="server")

device_order = {
    "light_key":1,
    "light_color":2,
}
bodyData = {
    "device_ID" : 1234,
    "device_order" : device_order
}

bodyData_json = json.dumps(bodyData)
#发送数据，发送一条，如果要发送多条则复制此段
channelx.basic_publish(exchange="",
                       routing_key="queue_rev",# 队列名
                       body = bodyData_json # 发送的数据
                       )
print("--------发送数据完成-----------")

#关闭连接
conn.close()
